package com.mybatis.config;

import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.spring.boot.MyBatisFlexCustomizer;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @desc: mybatis-Flex全局配置
 * @projectName: mybatis-generator-parent
 * @author: xhs
 * @date: 2023-09-13 013 17:46
 * @version: JDK 1.8
 */
@Configuration
public class MyBatisFlexConfig implements MyBatisFlexCustomizer {
    @Resource
    private ConsoleMessageCollector consoleMessageCollector;
    @Resource
    private ConsoleMessageReporter consoleMessageReporter;

    @Override
    public void customize(FlexGlobalConfig flexGlobalConfig) {
        // 开启审计功能
        AuditManager.setAuditEnable(true);

        // 设置SQL审计收集器
        AuditManager.setMessageReporter(consoleMessageReporter);

        // 设置SQL输出到控制台
        AuditManager.setMessageCollector(consoleMessageCollector);
    }
}
